<template>
  <div class="app-container">
    <el-form :model="searchForm" :inline="true">
      <el-row>
        <el-col :span="25">
          <el-form-item prop="fuzzy">
            <el-input
              v-model="searchForm.fuzzy"
              style="width: 250px"
              placeholder="仪器名称/仪器编号/仪器型号/仪器品牌"
            />
          </el-form-item>
          <el-form-item prop="type" label="仪器类别:">
            <el-select
              v-model="searchForm.type"
              style="width: 145px"
              placeholder="请选择仪器类别"
              clearable
            >
              <el-option
                v-for="item in typleList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="classType" label="检测类别:">
            <el-select
              v-model="searchForm.classType"
              style="width: 145px"
              placeholder="请选择检测类别"
              clearable
            >
              <el-option
                v-for="item in classTypeList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              class="iconfont icon-chaxun1"
              size="small"
              @click="handlesearch"
            >
              查询</el-button
            >
            <el-button type="primary" size="small" @click="instrumentData"
              >批量出库</el-button
            >
            <el-button type="primary" size="small" @click="storageData"
              >批量入库</el-button
            >
            <el-button type="primary" size="small" @click="oneClickstorage"
              >一键入库</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div>
      <el-table
        stripe
        border
        :data="factorData"
        class="table-item"
        highlight-current-row
        :header-cell-style="{ background: '#ECF3FC' }"
        style="width: 100%"
        @selection-change="handleselectionChange"
      >
        <template slot="empty">
          <div class="table_empty">
            <div class="empty_tips">
              <span> 暂无数据 </span>
            </div>
          </div>
        </template>
        <el-table-column
          type="selection"
          fixed="left"
          width="55"
          align="center"
        />
        <el-table-column type="index" width="70" align="center" label="序号" />
        <el-table-column
          prop="number"
          label="仪器编号"
          width="180"
          align="center"
        />
        <el-table-column
          prop="name"
          label="仪器名称"
          width="130"
          align="center"
        />
        <el-table-column
          prop="model"
          label="仪器型号"
          width="120"
          align="center"
        />
        <el-table-column
          prop="manufacturer"
          label="生产厂家"
          width="100"
          align="center"
        />
        <el-table-column
          prop="type"
          label="仪器类别"
          width="110px"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.type == '1'">现场采样仪器</span>
            <span v-if="scope.row.type == '2'">现场检测仪器</span>
            <span v-if="scope.row.type == '3'">实验室仪器</span>
            <span v-if="scope.row.type == '4'">校准仪器</span>
            <span v-if="scope.row.type == '5'">样品制备仪器</span>
          </template>
        </el-table-column>

        <el-table-column
          prop="classType"
          label="检测类别"
          min-width="100px"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.classType == '1'"> 水</span>
            <span v-if="scope.row.classType == '2'">气</span>
            <span v-if="scope.row.classType == '3'">噪声</span>
            <span v-if="scope.row.classType == '4'"
              >土壤、底泥、固废、污泥和生活垃圾</span
            >
            <span v-if="scope.row.classType == '5'">样品制备</span>
            <span v-if="scope.row.classType == '6'">小型分析仪器</span>
            <span v-if="scope.row.classType == '7'">色谱仪 </span>
            <span v-if="scope.row.classType == '8'">光谱仪</span>
            <span v-if="scope.row.classType == '9'">质谱仪</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="position"
          label="放置地点"
          width="100"
          align="center"
        />

        <el-table-column
          prop="projectName"
          label="项目名称"
          width="140"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="申领时间"
          width="140"
          align="center"
        >
        </el-table-column>

        <el-table-column
          prop="createUserName"
          label="申领人"
          width="190"
          align="center"
        >
        </el-table-column>

        <el-table-column
          prop="startDate"
          label="领用时间"
          width="180"
          align="center"
        />
        <el-table-column
          prop="returnDate"
          label="应归还时间"
          width="180"
          align="center"
        />
        <el-table-column
          prop="applyUser"
          label="领用人"
          width="120"
          align="center"
        />
        <el-table-column
          prop="applyStatus"
          label="出入库状态"
          width="100"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.applyStatus == '1'"
              style="color: green; font-weight: bold"
              >在库</span
            >
            <span
              v-if="scope.row.applyStatus == '2'"
              style="color: orange; font-weight: bold"
              >待出库</span
            >
            <span
              v-if="scope.row.applyStatus == '3'"
              style="color: red; font-weight: bold"
              >已出库</span
            >
          </template>
        </el-table-column>
        <el-table-column fixed="right" align="center" label="操作" width="200">
          <template slot-scope="scope">
            <el-button type="text" @click="view(scope.row)"> 查看</el-button>
            <div class="erc-divider-vertical" />
            <el-button
              type="text"
              v-if="scope.row.applyStatus == '3'"
              @click="storage(scope.row)"
            >
              入库</el-button
            >
            <el-button
              type="text"
              v-if="scope.row.applyStatus == '1'"
              @click="instrument(scope.row)"
            >
              出库</el-button
            >
            <div class="erc-divider-vertical" />
            <el-button
              Permi="['order:list:add']"
              type="text"
              @click="handleTransfer(scope.row)"
            >
              查看使用记录</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 出库 -->
    <el-dialog
      :title="titletTit[customerDialog]"
      :data="factorData"
      :visible.sync="transferDialogVisible"
      width="600px"
      center
      :close-on-click-modal="false"
    >
      <el-form
        ref="transferDialog"
        :rules="rules"
        :model="transferDialog"
        label-width="150px"
      >
        <el-row :gutter="20">
          <el-col :span="15">
            <el-form-item label="任务单号:" prop="jobId">
              <el-select
                v-model="transferDialog.jobId"
                style="width: 160%"
                clearable
              >
              <el-option value="" label="暂不选择"></el-option>
                <el-option
                  label="请选择"
                  v-for="item in deptList"
                  :key="item.jobId"
                  :label="`${item.jobId}  |  ${item.projectName}`"
                  :value="{ jobId: item.jobId, projectName: item.projectName }"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="15">
            <el-form-item prop="createUserName" label="申领人:">
              <!-- <el-input
                v-model="transferDialog.createUserName"
                style="width: 160%"
                placeholder="请输入领用人"
              /> -->
              <el-select
                v-model="custodianId"
                placeholder="请选择"
                filterable
                value-key="userId"
                @change="handleChecked"
                style="width:160%"
              >
                <el-option
                  v-for="item in usernameOptions"
                  :key="item.userId"
                  :label="item.empName"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="15">
            <el-form-item label="预计使用日期:" prop="sampleDate">
              <el-date-picker
                v-model="transferDialog.sampleDate"
                style="width: 160%"
                type="daterange"
                range-separator="至"
                value-format="yyyy-MM-dd"
                startTime-placeholder="开始日期"
                endDate-placeholder="结束日期"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="15">
            <el-form-item prop="applyUser" label="领用人:">
              <el-input
                v-model="transferDialog.applyUser"
                style="width: 160%"
                placeholder="请输入领用人"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="transferDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmData()">确认</el-button>
      </div>
    </el-dialog>
    <!-- 入库 -->
    <el-dialog
      :title="titleMap[customerDialogstatus]"
      :data="factorData"
      :visible.sync="storageVisible"
      width="600px"
      center
      :close-on-click-modal="false"
      :tree-props="{ children: 'childList', hasChildren: 'hasChildren' }"
    >
      <el-form
        ref="storagesearchForm"
        :model="storagesearchForm"
        label-width="150px"
        :rules="rules"
      >
        <el-row :gutter="20">
          <el-col :span="15">
            <el-form-item prop="position" label="放置地点:">
              <treeselect
                style="width: 160%"
                v-model="storagesearchForm.position"
                :options="deptOptions"
                :normalizer="normalizer"
                placeholder="选择放置地点"
                @select="changeId"
              />
            </el-form-item>
          </el-col>

          <el-col :span="15">
            <el-form-item prop="returnUser" label="仪器归还人:">
              <el-input
                v-model="storagesearchForm.returnUser"
                style="width: 160%"
                placeholder="请输入归还人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="15">
            <el-form-item prop="isIntact" label="核查结论:">
              <el-radio-group v-model="storagesearchForm.isIntact">
                <el-radio label="1">完好</el-radio>
                <el-radio label="2">损坏</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="storageVisible = false">取消</el-button>
        <el-button type="primary" @click="storageConfirms">确认</el-button>
      </div>
    </el-dialog>
    <!-- 一键入库 -->
    <el-dialog
      title="一键入库"
      :data="factorData"
      :visible.sync="storageVisibleData"
      width="600px"
      center
      :close-on-click-modal="false"
      :tree-props="{ children: 'childList', hasChildren: 'hasChildren' }"
    >
      <el-form ref="storagesearch" :model="storagesearch" label-width="150px">
        <el-row :gutter="20">
          <el-col :span="15">
            <el-form-item prop="position" label="放置地点:">
              <treeselect
                style="width: 160%"
                v-model="storagesearch.position"
                :options="deptOptions"
                :normalizer="normalizer"
                placeholder="选择放置地点"
                @select="changeIdData"
              />
            </el-form-item>
          </el-col>

          <el-col :span="15">
            <el-form-item prop="returnUser" label="仪器归还人:">
              <el-input
                v-model="storagesearch.returnUser"
                style="width: 160%"
                placeholder="请输入归还人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="15">
            <el-form-item prop="isIntact" label="核查结论:">
              <el-radio-group v-model="storagesearch.isIntact">
                <el-radio label="1">完好</el-radio>
                <el-radio label="2">损坏</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="storageVisibleData = false">取消</el-button>
        <el-button type="primary" @click="storageConfirm">确认</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="仪器使用历史记录"
      :visible.sync="transferVisible"
      width="65%"
      center
      :close-on-click-modal="false"
    >
      <div class="install-title">仪器基础信息</div>
      <el-form label-width="80px">
        <el-row :gutter="14">
          <el-col :span="6">
            <el-form-item label="仪器编号:">
              {{ chooseSearchForm.number }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="仪器名称:">
              {{ chooseSearchForm.name }}</el-form-item
            >
          </el-col>
          <el-col :span="6">
            <el-form-item label="型号规格:">
              {{ chooseSearchForm.model }}</el-form-item
            >
          </el-col>
          <el-col :span="6">
            <el-form-item label="生产厂家:">
              {{ chooseSearchForm.manufacturer }}</el-form-item
            >
          </el-col>
        </el-row>
        <el-row :gutter="12">
          <el-col :span="6">
            <el-form-item label="仪器类别:">
              <span v-if="chooseSearchForm.type == '1'">现场采样仪器</span>
              <span v-if="chooseSearchForm.type == '2'">现场检测仪器</span>
              <span v-if="chooseSearchForm.type == '3'">实验室仪器</span>
              <span v-if="chooseSearchForm.type == '4'">校准仪器</span>
              <span v-if="chooseSearchForm.type == '5'">样品制备仪器</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="检测类别:">
              <span v-if="chooseSearchForm.classType == '1'"> 水</span>
              <span v-if="chooseSearchForm.classType == '2'">气</span>
              <span v-if="chooseSearchForm.classType == '3'">噪声</span>
              <span v-if="chooseSearchForm.classType == '4'"
                >土壤、底泥、固废、污泥和生活垃圾</span
              >
              <span v-if="chooseSearchForm.classType == '5'">样品制备</span>
              <span v-if="chooseSearchForm.classType == '6'">小型分析仪器</span>
              <span v-if="chooseSearchForm.classType == '7'">色谱仪 </span>
              <span v-if="chooseSearchForm.classType == '8'">光谱仪</span>
              <span v-if="chooseSearchForm.classType == '9'">质谱仪</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div
        style=" 
          display: flex;
          align-items: center;
          line-height: 50px;
          padding-left: 20px;
          color: #fff;
          background-color: #d7dae2;
          flex-wrap: wrap;
          justify-content: space-between
          margin-bottom: 10px;"
      >
        <div>仪器使用记录</div>
        <div class="block" style="margin: 0 40px 0 0">
          <span class="demonstration">日期选择：</span>
          <el-date-picker
            type="daterange"
            v-model="startEnd"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="changeStartEnd"
          >
          </el-date-picker>
        </div>
      </div>
      <el-table
        :model="searchForm"
        border
        stripe
        :data="transferTableData"
        highlight-current-row
        :header-cell-style="{ background: '#ECF3FC' }"
        style="width: 100%"
        ref="transferTableData"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          fixed="left"
          width="55"
          align="center"
        />
        <el-table-column
          type="index"
          width="50"
          label="序号"
          fixed="left"
          align="center"
        />
        <el-table-column
          prop="jobId"
          label="任务单号"
          width="150"
          fixed="left"
          align="center"
        />
        <el-table-column
          prop="projectName"
          label="项目名称"
          width="120"
          align="center"
        />

        <el-table-column
          prop="classType"
          label="检测项目"
          width="110px"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.classType == '1'"> 水</span>
            <span v-if="scope.row.classType == '2'">气</span>
            <span v-if="scope.row.classType == '3'">噪声</span>
            <span v-if="scope.row.classType == '4'"
              >土壤、底泥、固废、污泥和生活垃圾</span
            >
            <span v-if="scope.row.classType == '5'">样品制备</span>
            <span v-if="scope.row.classType == '6'">小型分析仪器</span>
            <span v-if="scope.row.classType == '7'">色谱仪 </span>
            <span v-if="scope.row.classType == '8'">光谱仪</span>
            <span v-if="scope.row.classType == '9'">质谱仪</span>
          </template>
        </el-table-column>

        <el-table-column
          prop="createUserName"
          label="申领人"
          width="100"
          align="center"
        />
        <el-table-column
          prop="applyUser"
          label="领用人"
          width="110"
          align="center"
        />
        <el-table-column
          prop="returnUser"
          label="归还人"
          width="110px"
          align="center"
        />
        <el-table-column
          prop="applyTime"
          label="领用时间"
          width="110px"
          align="center"
        />
        <el-table-column
          prop="returnTime"
          label="归还时间"
          width="100px"
          align="center"
        />
        <el-table-column
          prop="isIntact"
          label="归还后仪器状况"
          width="120px"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.isIntact == '1'"
              style="background: #13CE66;padding: 20px;color: #fff;;"
              >正常</span
            >
            <span
              v-if="scope.row.isIntact == '2'"
              style="background: #ff1100;padding: 20px;color: #fff;;"
              >异常</span
            >
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="transferVisible = false">取消</el-button>
        <el-button type="primary" @click="handleDownloadData()"
          >使用记录下载</el-button
        >
      </div>
    </el-dialog>

    <!-- 查看 -->
    <el-dialog
      title="查看"
      :visible.sync="MyInstrumentView"
      center
      top="5vh"
      width="1400px"
    >
      <div>
        <div class="install-title">出入库列表基础信息</div>
        <el-form label-width="130px">
          <el-row :gutter="12">
            <el-col :span="8">
              <el-form-item prop="number" label="仪器编号:">
                {{ ViewForm.number }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="name" label="仪器名称:">
                {{ ViewForm.name }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="model" label="仪器型号:">
                {{ ViewForm.model }}
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item prop="manufacturer" label="生产厂家:">
                {{ ViewForm.manufacturer }}
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item prop="type" label="仪器类别:">
                <el-form-item>
                  <span v-if="ViewForm.type == '1'">现场采样仪器</span>
                  <span v-if="ViewForm.type == '2'">现场检测仪器</span>
                  <span v-if="ViewForm.type == '3'">实验室仪器</span>
                  <span v-if="ViewForm.type == '4'">校准仪器</span>
                  <span v-if="ViewForm.type == '5'">样品制备仪器</span>
                </el-form-item>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item prop="classType" label="检测类别:">
                <span v-if="ViewForm.classType == '1'"> 水</span>
                <span v-if="ViewForm.classType == '2'">气</span>
                <span v-if="ViewForm.classType == '3'">噪声</span>
                <span v-if="ViewForm.classType == '4'"
                  >土壤、底泥、固废、污泥和生活垃圾</span
                >
                <span v-if="ViewForm.classType == '5'">样品制备</span>
                <span v-if="ViewForm.classType == '6'">小型分析仪器</span>
                <span v-if="ViewForm.classType == '7'">色谱仪 </span>
                <span v-if="ViewForm.classType == '8'">光谱仪</span>
                <span v-if="ViewForm.classType == '9'">质谱仪</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="position" label="放置地点:">
                {{ ViewForm.position }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="projectName" label="项目名称:">
                {{ ViewForm.projectName }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="申领时间:" prop="createTime">
                {{ ViewForm.createTime }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="createUserName" label="申领人:">
                {{ ViewForm.createUserName }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="startDate" label="领用时间:">
                {{ ViewForm.startDate }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="returnDate" label="应归还时间:">
                {{ ViewForm.returnDate }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="applyUser" label="领用人:">
                {{ ViewForm.applyUser }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="status" label="出入库状态:">
                <template>
                  <span
                    v-if="ViewForm.status == '1'"
                    style="color: green;font-weight: bold"
                    >在库</span
                  >
                  <span
                    v-if="ViewForm.status == '2'"
                    style="color: red;font-weight: bold"
                    >待出库
                  </span>
                  <span
                    v-if="ViewForm.status == '3'"
                    style="color: red;font-weight: bold"
                    >已出库
                  </span>
                </template>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-dialog>

    <div style="float: right">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="searchForm.pageNumber"
        :limit.sync="searchForm.pagesize"
        @pagination="handlesearch"
      />
    </div>
  </div>
</template>

<script>
import * as List from "@/api/List";
import * as api from "@/api/Accesslist";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import Treeselect from "@riophae/vue-treeselect";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
export default {
  components: { Pagination, Treeselect },
  filters: {},
  data() {
    return {
      minTime: "",
      maxTime: "",
      pickerOptions: {
        disabledDate: date => {
          let minTime = this.startDate;
          let maxTime = this.endDate;
          // 2021-07-11 至 2021-07-13 禁选，返回true代表禁用
          if (
            date.getTime() > new Date(minTime) &&
            date.getTime() < new Date(maxTime)
          ) {
            return true;
          }
          // 设置过去时间不可选，返回true代表禁用
          //let zero=new Date().setHours(0, 0, 0, 0);
          //if(date.getTime()<zero){
          //  return true;
          //}
          return false;
        }
      },
      transferTableData: [],
      limit: 5,
      total: 0,
      isLook: false,
      factorData: [], //数据
      deptList: [], //下拉框数据
      ViewForm: [],
      // 部门树选项
      deptOptions: [],
      storagesearchForm: {
        deviceIds: [],
        isIntact: "1",
        position: null,
        returnUser: ""
      },
      custodianId: [],
      usernameOptions: [],
      storagesearch: {
        deviceIds: [],
        deviceUsesubIds: "",
        deviceUseId: "",
        isIntact: "1",
        position: null,
        returnUser: ""
      },
      transferDialog: {
        createUser: "",
        createUserName: ""
      },
      startEnd: [],
      chooseSearchForm: {},
      transferDialogVisible: false,
      transferVisible: false,
      storageVisible: false,
      MyInstrumentView: false,
      storageVisibleData: false,
      rules: {
        jobId: [
          { required: true, message: "任务单号不能为空", trigger: "blur" }
        ],
        createUserName: [
          { required: true, message: "申领人不能为空", trigger: "blur" }
        ],
        sampleDate: [
          { required: true, message: "预计使用日期不能为空", trigger: "blur" }
        ],
        applyUser: [
          { required: true, message: "领用人不能为空", trigger: "blur" }
        ],
        position: [
          { required: true, message: "放置地点不能为空", trigger: "blur" }
        ],
        returnUser: [
          { required: true, message: "仪器归还人不能为空", trigger: "blur" }
        ],
        isIntact: [
          { required: true, message: "核查结论人不能为空", trigger: "blur" }
        ]
      },
      typleList: [
        {
          name: "现场采样仪器",
          id: 1
        },
        {
          name: "现场检测仪器",
          id: 2
        },
        {
          name: "实验室仪器",
          id: 3
        },
        {
          name: "校准仪器",
          id: 4
        }
      ],
      classTypeList: [
        {
          name: "水",
          id: 1
        },
        {
          name: "气",
          id: 2
        },
        {
          name: "噪声",
          id: 3
        },
        {
          name: "土壤、底泥、固废、污泥和生活垃圾",
          id: 4
        },
        {
          name: "样品制备",
          id: 5
        },
        {
          name: "小型分析仪器",
          id: 6
        },
        {
          name: "色谱仪",
          id: 7
        },
        {
          name: "光谱仪",
          id: 8
        },
        {
          name: "质谱仪",
          id: 9
        }
      ],
      searchForm: {
        pageNumber: 1,
        pagesize: 10
      },
      searchForm1: {
        pageNumber: 1,
        pagesize: 10,
        id: ""
      },
      selection: [],
      titleMap: {
        edit: "入库",
        create: "批量入库"
      },
      titletTit: {
        edit: "出库",
        create: "批量出库"
      },
      customerDialogstatus: "create",
      customerDialog: "create",
      deviceIds: [],
      multipleselection: []
    };
  },
  created() {
    this.handlesearch();
  },
  methods: {
    handlesearch() {
      //   console.log(123);
      api.deviceManageList(this.searchForm).then(res => {
        // console.log(res);
        if (res.code === 200) {
          this.factorData = res.result.records;
          console.log(this.factorData);
          this.total = res.result.total;
        }
      });
      // 位置列表
      api.roomList().then(res => {
        this.deptListRoomList = res.result;
        console.log(this.deptListRoomList);
        this.deptOptions = this.deptListRoomList;
        console.log(this.deptOptions);
      });
    },
    changeId(e) {
      console.log(e);
      this.storagesearchForm.position = e.name;
    },
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.childList && !node.childList.length) {
        delete node.childList;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.childList
      };
    },
    // 获取列表勾中id
    handleselectionChange(val) {
      console.log(val);
      this.multipleselection = val;
      var arr = [];
      for (var item of val) {
        // console.log(item.id);
        arr.push(item.id);
        // console.log(arr + []);
        this.selection = arr;
        console.log(this.selection);
      }
    },

    // 单个出库弹框
    instrument(row) {
      this.customerDialog = "edit";
      console.log(row);
      this.transferDialog.id = row.id;
      this.transferDialogVisible = true;
      //下拉框数据
      api.jobList().then(res => {
        this.deptList = res.result;
        console.log(this.deptList);
      });
      //用过时间
      api.getUseTime({ deviceId: this.transferDialog.id }).then(res => {
        if (res.code === 200) {
          console.log(111, res);
          this.startDate = res.result[0];
          this.endDate = res.result.slice(-1)[0];
          // console.log(this.startDate);
          // console.log(this.endDate);
        }
      });
      //人
      List.userList().then(res => {
        this.usernameOptions = res.result;
      });
    },
    // 批量出库弹框
    instrumentData() {
      this.customerDialog = "create";
      if (this.multipleselection && this.multipleselection.length === 0) {
        this.$message.warning("请选择仪器");
      } else {
        this.transferDialogVisible = true;
        //下拉框数据
        api.jobList().then(res => {
          this.deptList = res.result;
          console.log(this.deptList);
        });
      }
    },
    //选择人
    handleChecked(val) {
      console.log(val);
      this.transferDialog.createUserName = val.empName;
      this.transferDialog.createUser = val.userId;
    },
    // 单个出库 & 批量出库
    confirmData() {
      this.$refs.transferDialog.validate(valid => {
        if (valid) {
          api
            .issue({
              startTime: this.transferDialog.sampleDate[0],
              endDate: this.transferDialog.sampleDate[1],
              jobId: this.transferDialog.jobId.jobId,
              projectName: this.transferDialog.jobId.projectName,
              applyUser: this.transferDialog.applyUser,
              deviceIds: this.transferDialog.id.split()
            })
            .then(request => {
              this.$notify({
                title: "成功",
                message: request.message,
                type: "success"
              });
              this.handlesearch();
              this.transferDialogVisible = false;
              this.$refs.searchForm.resetFields();
            })
            .catch(() => {});
        } else {
          return false;
        }
      });
    },

    // 单个入库弹框
    storage(row) {
      this.customerDialogstatus = "edit";
      console.log(row);
      this.storageVisible = true;
      this.storagesearchForm.deviceIds = row.id.split();
      console.log(this.storagesearchForm.deviceIds);
    },
    // 批量入库弹框
    storageData() {
      this.customerDialogstatus = "create";
      if (this.multipleselection && this.multipleselection.length === 0) {
        this.$message.warning("请选择仪器");
      } else {
        this.storageVisible = true;
        this.storagesearchForm.deviceIds = this.selection;
      }
    },

    // 单个入库 & 批量入库
    storageConfirms() {
      // this.$refs.storagesearchForm.validate(valid => {
      //   if (valid) {
      //     api
      //       .sendBack(this.storagesearchForm)
      //       .then(request => {
      //         this.$notify({
      //           title: "成功",
      //           message: request.message,
      //           type: "success"
      //         });
      //         this.handlesearch();
      //         this.storageVisible = false;
      //         this.$refs.searchForm.resetFields();
      //       })
      //       .catch(() => {});
      //   } else {
      //     return false;
      //   }
      // });
      api.sendBack(this.storagesearchForm).then(res => {
        console.log(res);
        if (res.code === 200) {
          this.$notify({
            title: "成功",
            message: res.message,
            type: "success"
          });
          this.handlesearch();
          this.storageVisible = false;
        } else {
          this.$notify({
            title: "失败",
            message: res.message,
            type: "error"
          });
          this.approveVisible = false;
        }
      });
    },
    // 一键入库
    oneClickstorage() {
      this.storageVisibleData = true;
    },
    changeIdData(e) {
      console.log(e);
      this.storagesearch.position = e.name;
    },
    // 一键入库
    storageConfirm() {
      api
        .sendBack(this.storagesearch)
        .then(request => {
          this.$notify({
            title: "成功",
            message: request.message,
            type: "success"
          });
          this.handlesearch();
          this.storageVisibleData = false;
        })
        .catch(() => {});
    },
    //查看使用记录
    handleTransfer(row) {
      this.chooseSearchForm = row;
      console.log(this.chooseSearchForm);
      this.searchForm1.id = row.id;
      this.transferVisible = true;
      api.deviceUseDetail(this.searchForm1).then(res => {
        if (res.code === 200 && res.result) {
          // console.log(res);
          this.transferTableData = res.result.records || [];
          this.total = res.result.total;
        }
      });
    },
    changeStartEnd() {
      console.log(this.startEnd);
      if (this.startEnd.length != 0) {
        this.searchForm.start = this.startEnd[0];
        this.searchForm.end = this.startEnd[1];
        api.deviceUseDetail(this.searchForm).then(res => {
          if (res.code === 200 && res.result) {
            // console.log(res);
            this.transferTableData = res.result.records || [];
            this.total = res.result.total;
          }
        });
      }
    },
    handleDownloadData() {
      if (this.multipleselection.length != 0) {
        var url =
          "/api/excel/exportUseList?id=" +
            this.Selection +
            "&type=" +
            "2" +
            "&start=" +
            this.searchForm.start ||
          "" + "&end=" + this.searchForm.end ||
          "";
        window.open(url);
        this.transferDialogVisible = false;
        this.searchForm.start = "";
        this.searchForm.end = "";
        this.startEnd = "";
      } else {
        var url =
          "/api/excel/exportUseList?id=" +
            this.searchForm1.id +
            "&type=" +
            "1" +
            "&start=" +
            this.searchForm.start ||
          "" + "&end=" + this.searchForm.end ||
          "";
        window.open(url);
        this.transferDialogVisible = false;
        this.searchForm.start = "";
        this.searchForm.end = "";
        this.startEnd = "";
      }
    },
    // 查看
    view(row) {
      console.log(row);
      this.MyInstrumentView = true;
      this.ViewForm = row;
    }
  }
};
</script>

<style scoped lang="scss">
.clearfix {
  line-height: 40px;
  display: flex;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.clearfix {
  line-height: 40px;
  display: flex;
}
.install-title {
  display: flex;
  align-items: center;
  line-height: 40px;
  padding-left: 20px;
  color: rgb(15, 14, 14);
  background-color: #d7dae2;
  justify-content: flex-start;
  margin-top: 15px;
}
.delete {
  width: 10px;
  height: 10px;
  position: relative;
  top: -10px;
  cursor: pointer;
}
::v-deep .el-upload-list {
  width: 100px;
  display: flex;
  margin: 10px 10px;
}
::v-deep .el-upload-list > li {
  margin: 10px 10px;
}
::v-deep.el-upload-list__item {
  margin: 10px 10px;
}
::v-deep.el-upload-list--picture .el-upload-list__item {
  margin: 10px 10px !important;
}
.user-info-head {
  position: relative;
  display: inline-block;
  height: 120px;
}

::v-deep.avatar-upload-preview {
  width: 400px;
  border-radius: 0%;
  height: 400px;
  > img {
    transform: translateX(0);
  }
}
.user-info-head:hover:after {
  content: "+";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  color: #eee;
  background: rgba(0, 0, 0, 0.5);
  font-size: 24px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  cursor: pointer;
  line-height: 110px;
  border-radius: 50%;
}
</style>
